import Vue from 'vue'
import Router from 'vue-router'
const login = r => require.ensure([], () => r(require('@/Modules/login')), 'login')
const lazy  = r => require.ensure([], () => r(require('@/Modules/lazy')), 'lazy')
const home  = r => require.ensure([], () => r(require('@/Modules/Home/home')), 'home')

Vue.use(Router)
const router = new Router({
  routes: [
    { path: '/home', name: 'home', component: home ,meta: { requiresAuth: true } },
	{ path: '/lazy', name: 'lazy', component: lazy ,meta: { requiresAuth: true } },
    { path: '/', name: 'login', component: login },
    { path: '', redirectTo: '/', pathMatch: 'full'},
    { path: '**', component: login }
  ]
})
router.beforeEach((to, from, next) => {
	console.log();
	if(to.matched.some(route=>route.meta.requiresAuth)){
		if(localStorage.getItem("VUELogin") == 'true'){
		  	next();
		}else{
		  next({ path:'/' });
		}
	}else{
		next();
	}
})
export default router
